<template>
  <div>
    <el-card class="search-card">
      <el-form
        :model="queryParams"
        ref="queryForm"
        size="small"
        :inline="true"
        label-width="68px"
      >
        <el-row :gutter="10">
          <el-col :span="7.5">
            <el-form-item label="插件名称" prop="pluginName">
              <el-input
                placeholder="请输入插件名称"
                v-model="queryParams.pluginName"
                class="input-width"
              >
                <!-- <el-button slot="append" icon="el-icon-search"></el-button> -->
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="7.5">
            <el-form-item label="插件分类" prop="pluginType">
              <el-select
                v-model="queryParams.pluginType"
                clearable
                placeholder="请选择插件分类"
                class="input-width"
              >
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="1.5">
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="handleQuery"
              >搜索</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
              >重置</el-button
            ></el-col
          >
        </el-row>
      </el-form>
      <el-row :gutter="10">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
            >新增</el-button
          >
        </el-col>
      </el-row>
    </el-card>
    <el-card style="margin-top: 10px">
      <!-- <div class="plugin-h">
        <div></div>
      </div> -->
      <div class="plugin-list">
        <template v-for="item in 12">
          <PluginCard />
        </template>

        <!-- <div class="plugin-l"></div>
        <div class="plugin-r"></div> -->
      </div>
      <pagination
        :total="total"
        :page-size="12"
        :page-sizes="[12, 24, 48]"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-card>

    <!-- 分配角色数据权限对话框 -->
    <el-dialog :title="title" :visible.sync="open" append-to-body width="800px">
      <el-form :model="form" label-width="80px" class="item-width">
        <el-form-item label="插件图片:">
          <el-upload
            class="avatar-uploader"
            action="https://jsonplaceholder.typicode.com/posts/"
            :show-file-list="false"
            :on-success="handleAvatarSuccess"
            :before-upload="beforeAvatarUpload"
          >
            <img v-if="form.imageUrl" :src="form.imageUrl" class="avatar" />
            <i v-else class="el-icon-plus avatar-uploader-icon"></i> </el-upload
        ></el-form-item>
        <el-row :gutter="10">
          <el-col :span="12">
            <el-form-item label="插件名称">
              <el-input
                v-model="form.pluginName"
                placeholder="请输入插件名称"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="插件分类" prop="pluginType">
              <el-select
                v-model="form.pluginType"
                clearable
                placeholder="请选择插件分类"
              >
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="10">
          <el-col :span="12">
            <el-form-item label="发布科室">
              <el-select
                v-model="form.pluginType"
                clearable
                placeholder="请选择插件分类"
              >
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12"> </el-col>
        </el-row>

        <el-form-item label="上传插件">
          <globalUploader />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitClick">确 定</el-button>
        <el-button @click="cancelClick">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import PluginCard from "./component/PluginCard.vue";
import globalUploader from "./component/globalUploader.vue";
export default {
  data() {
    return {
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 12,
        pluginName: "", //插件名称
        pluginType: "", // 插件分类
      },
      // 分类选项
      options: [
        {
          value: 0,
          label: "可执行类插件",
        },
        {
          value: 1,
          label: "Web类插件",
        },
        {
          value: 2,
          label: "镜像类插件",
        },
      ],
      //图片封面

      // 表单参数
      form: {},
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 插件列表
      pluginList: [],
      // 弹窗控制
      open: false,
      // 弹窗标题
      title: "",
    };
  },
  components: {
    PluginCard,
    globalUploader,
  },
  methods: {
    /** 查询公告列表 */
    getList() {
      this.loading = true;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加插件";
    },
    // 添加插件
    submitClick() {},
    // 取消
    cancelClick() {
      this.reset();
      this.form = {};
      this.open = false;
    },

    // 重置表单
    reset() {
      this.resetForm("form");
    },
    // -----------------图片介绍上传-------------------------
    handleAvatarSuccess(res, file) {
      this.imageUrl = URL.createObjectURL(file.raw);
    },
    beforeAvatarUpload(file) {
      const isJPG = file.type === "image/jpeg";
      const isLt5M = file.size / 1024 / 1024 < 5;

      if (!isJPG) {
        this.$message.error("上传头像图片只能是 JPG 格式!");
      }
      if (!isLt5M) {
        this.$message.error("上传头像图片大小不能超过 2MB!");
      }
      return isJPG && isLt5M;
    },
    // -----------------------图片介绍上传end---------------------------
  },
  created() {},
  mounted() {},
};
</script>

<style lang="scss" scoped>
.search-card {
  min-height: 100px;
}

::v-deep .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
::v-deep .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 138px;
  height: 138px;
  line-height: 138px;
  text-align: center;
}
.avatar {
  width: 138px;
  height: 138px;
  display: block;
}

.plugin-h {
  position: relative;
  display: flex;
  justify-content: center;

  .title {
    position: absolute;
    left: 0;
    // font-weight: bold;
    top: 50%;
    transform: translateY(-50%);
  }
}
.input-width {
  width: 300px;
}
.item-width {
  .el-input,
  .el-select {
    width: 240px;
  }
}

// .plugin-content {
//   display: flex;
//   justify-content: space-between;

//   .plugin-l {
//     height: 80vh;
//     background: pink;
//     width: 200px;

//   }
// }

.plugin-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}

@media (max-width: 1200px) {
  .input-width {
    width: 200px;
  }
  /* 小于600px宽度时 */
  .plugin-list {
    grid-template-columns: repeat(2, 1fr);
    /* 每行2列 */
  }
}

@media (max-width: 800px) {
  .input-width {
    width: 200px;
  }
  /* 小于400px宽度时 */
  .plugin-list {
    grid-template-columns: 1fr;
    /* 每行1列 */
  }
}
</style>
